home *** CD-ROM | disk | FTP | other *** search
-
- UN-CGI VERSION 1.2
-
- Contents
-
- * Introduction
- * Installation
- * Usage
- * Other Features
- * Bugs
- * Frequently Asked Questions
-
- Introduction
-
-
-
- This is uncgi 1.1, a frontend for processing queries and forms from
- the Web on UNIX systems. You can get it via anonymous ftp from
- ftp.hyperion.com or, depending on your browser, by following this
- link.
-
- Without this program, if you wanted to process a form, you'd have to
- either write or dig up routines to translate the values of the form's
- fields from "URL encoding" to whatever your program required. This was
- a hassle in C, and a real pain in the shell, and you had do things
- differently for GET and POST queries.
-
- Which is where uncgi comes in. It decodes all the form fields and
- sticks them into environment variables for easy perusal by a shell
- script, a C program, a Perl script, or whatever you like, then
- executes whatever other program you specify.
-
- (Actually, "uncgi" is something of a misnomer, as the weird URL syntax
- is from the HTML forms specification, not from CGI itself.)
-
- Installation
-
-
-
- To install, edit the Makefile, setting "CGI_BIN" to point to your HTTP
- server's CGI directory. Under NCSA httpd, this is usually a directory
- called "cgi-bin" in the server root directory. Then run "make
- install".
-
- Note that the variable serves two purposes as supplied: it tells the
- Makefile where to install uncgi, and it also tells uncgi where to look
- for backend scripts. If you would like uncgi to look in a directory
- other than the one it's installed in, set DESTDIR to the install
- directory and CGI_BIN to the directory containing the scripts and
- programs that uncgi will be executing.
-
- Usage
-
-
-
- An example is the easiest way to demonstrate uncgi's use. Suppose you
- have the following in an HTML file:
-
- <form method=POST action="/cgi-bin/uncgi/myscript/thanks.html">
- What's your name?
- <input type=text size=30 name=name>
- <p>
- Type some comments.
- <br>
- <textarea name=comments rows=10 cols=60></textarea>
- What problem are you having? <select name=problem multiple>
- <option> Can't sleep
- <option> Unruly goat
- <option> Limousine overcrowding
- </select>
- <p>
- <input type=submit value=" Send 'em in! ">
- </form>
-
- When the user selects the "Send 'em in!" button, the HTTP server will
- run uncgi. Uncgi will set three environment variables, WWW_name,
- WWW_comments and WWW_problem, to the values of the "name", "comments",
- and "problem" fields in the form, respectively. Then it will execute
- myscript in the CGI_BIN directory. If more than one "problem" is
- selected, the values will all be placed in WWW_comments, separated by
- hash marks ('#').
-
- All the usual CGI environment variables (PATH_INFO, QUERY_STRING,
- etc.) are available to the script or program you tell uncgi to run. A
- couple of them (PATH_INFO and PATH_TRANSLATED) are tweaked by uncgi to
- the values they'd have if your program were being executed directly by
- the server. In the above example, when uncgi ran myscript, PATH_INFO
- would be set to "/thanks.html". This is an easy way to specify
- additional parameters to your script without resorting to hidden
- fields.
-
- Myscript might be as simple as this:
-
- #!/bin/sh
- echo 'Content-type: text/html'
- echo ''
- mail webmaster << __EOF__
- $WWW_name said:
- $WWW_comments
- __EOF__
- cat $PATH_TRANSLATED
-
- With uncgi, that's all you need to do to write a script to send you
- mail from a form and print a prewritten file as a response. And it's
- the same whether you want to use GET or POST queries.
-
- Other Features
-
-
-
- Extra feature: If you compile with -DNO_MAIN, you can use uncgi as a
- library function in a C program of your own. Just call uncgi() at the
- start of your program.
-
- Uncgi will handle hybrid GET/POST requests. Specify a method of POST
- in the form, and add a GET-style query string to the action, for
- example <form method=POST
- action="/cgi-bin/uncgi/myscript?form_id=feedback">. When your script
- is run, WWW_form_id will be set to "feedback". This will only work if
- your HTTP server supports it (NCSA's does, for now anyway.)
-
- Bugs
-
-
-
- There should be a way to specify a list of directories that uncgi will
- search for backend scripts.
-
- Frequently Asked Questions
-
- WHERE DO I PUT EVERYTHING?
-
-
-
- Short answer: Your server's cgi-bin directory.
-
- Long answer: When you edit uncgi's Makefile, you'll see two macro
- definitions. The first, CGI_BIN, tells uncgi where to look for your
- scripts or programs. It must be set to the name of an existing
- directory; you can set it to any directory you like. Usually it's set
- to the location of your server's cgi-bin directory.
-
- The second, DESTDIR, tells the Makefile where to install uncgi. By
- default, it's set to the same thing CGI_BIN is. It must point to your
- server's cgi-bin directory, so you'll need to change it if you set
- CGI_BIN to something else.
-
- WHY DOES UNCGI TELL ME IT CAN'T RUN MY SCRIPT?
-
-
-
- First, make sure your script is in the right place; see the preceding
- section.
-
- Second, make sure your script can be executed by the server. Remember,
- the server probably isn't running from your account, so you need to
- set the permissions on your script such that it can be run by any
- user. Usually, you can say "chmod 755 scriptname" (replacing
- scriptname with the name of your script) to set the permissions
- properly.
-
- WHAT DO I DO IN MY FORMS?
-
-
-
- The <form> tag has two attributes, METHOD and ACTION. METHOD must be
- set to either GET or POST; uncgi will handle either one, but POST is
- preferred if you have textarea fields or are expecting a lot of
- information from the client. Note that the attribute name (METHOD) can
- be upper or lower case, but the value must be all caps.
-
- ACTION should have the following components:
- * The alias for your server's cgi-bin directory (usually just
- /cgi-bin/)
- * uncgi/ to tell the server which program to execute.
- * The name of your script as it appears in the directory where you
- told uncgi to find your scripts and programs (the CGI_BIN macro in
- the Makefile.) Example: myscript
- * Optionally, a forward slash followed by additional parameters,
- often the path to another file you want your script to print. This
- path information will be available to your script in the PATH_INFO
- and PATH_TRANSLATED environment variables (the latter contains the
- full path to the document, including the path to the server root
- directory.) Note that you can't use tilde notation. Example:
- /form_output/acknowledge.html
-
-
-
- So, if you wanted to tell uncgi to run sendmemail with no additional
- parameters, you'd put sendmemail in the directory you specified as the
- value of CGI_BIN in uncgi's makefile, and use the following tag to
- begin your form:
-
- <form method=POST action="/cgi-bin/uncgi/sendmemail">
-
- I GET AN ERROR CODE 500 FROM THE SERVER.
-
-
-
- This usually means your script isn't specifying a content type to the
- server. The first thing your script needs to output is:
-
- Content-type: text/html
-
- followed by a blank line.
- _________________________________________________________________
-
- Maintained by Steven Grimm <koreth@hyperion.com>.
- Send mail if you have comments or suggestions.
-